<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class LogPageAccess {
    var $CI;

    function LogPageAccess() {
        $this->CI =& get_instance();
        $this->CI->load->model('model_log');
    }

    function index() {
        //controllere care nu sunt logate
        $aSafeControllers = array("cron", "login", "main", "provider","user","import","support");
        $aSafeFunctions = array("data/bringObject", "data/bringCompany", "baza/export", "baza/bringBaza");
        //primul segment de adresa URL
        $sController = $this->CI->uri->segment(1);
        $sFunction = $this->CI->uri->segment(2);
        $sUriString = $this->CI->uri->uri_string();  // returneaza adresa URL dar fara base url (domeniu)
        $aCurrentUser = $this->CI->usersession->currentUser();

        if ($sUriString == "") {
            return;
        }

        //nu se logheaza paginile de login,cron,main
        if (in_array($sController, $aSafeControllers)) {
            return;
        }

        //nu se logheaza functiile din $aSafeFunction
        if (in_array($sController."/".$sFunction, $aSafeFunctions)) {
            return;
        }

        if ($aCurrentUser === FALSE) {
            $iUserId = 0;
        }
        else {
            $iUserId = $aCurrentUser['user_id'];
            //modificare camp 'lastactivity'
            $this->CI->model_log->logLastActivity($iUserId);
        }

        // inserare log
        $this->CI->model_log->logPage($iUserId, $this->CI->input->ip_address(), $sUriString, json_encode($_POST));
    }
}
?>
